package com.shawn.example.mvvmdemo.home.ui.wx.viewholder

import android.view.View
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.shawn.example.mvvmdemo.home.R
import com.shawn.example.mvvmdemo.home.databinding.ItemSearchPagerBinding
import com.shawn.example.mvvmdemo.home.vo.FeedArticleData

class KnowledgeHierarchyListViewHolder(val view: View) : BaseViewHolder(view) {
    private var binding: ItemSearchPagerBinding = ItemSearchPagerBinding.bind(view)
    var isCollectPage = false
    var isSearchPage = false
    var isNightMode = false
    var mHasRecorded = false

    fun buildLayout(article: FeedArticleData) {
        binding.itemSearchPagerTitle.text = article.title
        if (article.isCollect || isCollectPage) {
            binding.itemSearchPagerLikeIv.setImageResource(R.drawable.icon_like)
        } else {
            binding.itemSearchPagerLikeIv.setImageResource(R.drawable.icon_like_article_not_selected)
        }
        binding.itemSearchPagerAuthor.text = article.author
        if (article.chapterName.isNotBlank()) {
            val classifyName: String = article.superChapterName + " / " + article.chapterName
            binding.itemSearchPagerChapterName.text = classifyName
        }
        binding.itemSearchPagerNiceDate.text = article.niceDate

        setTag()
    }

    private fun setTag() {
        binding.itemSearchPagerTagGreenTv.isVisible = false
        binding.itemSearchPagerTagRedTv.isVisible = false
        if (isCollectPage) {
            return
        }
    }

    private fun setRedTag(@StringRes tagName: Int) {
        binding.itemSearchPagerTagRedTv.isVisible = true
        binding.itemSearchPagerTagRedTv.setText(tagName)
        binding.itemSearchPagerTagRedTv.setTextColor(ContextCompat.getColor(view.context, R.color.light_deep_red))
        binding.itemSearchPagerTagRedTv.setBackgroundResource(R.drawable.selector_tag_red_background)
    }
}